home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: Philippe Verdy <100105.3120@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: How do I change the middle of a file?
- Date: 30 Mar 1996 02:23:02 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4ji5u6$eu0@dub-news-svc-3.compuserve.com>
- NNTP-Posting-Host: hd75-001.compuserve.com
-
- culbreth@cc.gatech.edu (Matthew W. Culbreth) s'Θcrit :
- > Howdy,
- >
- > I've got a big text file that acts as a database. I need to be able
- > to search through the file, find a particular line, and change it.
- >
- > I've tried opening the file in (ios::in|ios::app), but now the program
- > won't getline().
- >
- > Any ideas?
- >
- > Thanks,
- >
- > Matt
- >
- > --
- >
- > -Matthew W. Culbreth (culbreth@cc.gatech.edu)
- > -CS student
- > -Georgia Tech, College of Computing
- Text files are not structured, and have varying length records.
- So you cannot use them to change a line on the same place.
- The best thing to do is to recreate another text file with the
- altered line, then deleting the old one, and renaming the new one.
- If this copy is judged long, don't use varying length records.
-
- Open your file in binary mode, and store fixed length records,
- so that you can seek back to the beginning of the record you
- want to alter and that you have just read, prior to writing it
- safely in a place with enough space for your new record.
-
- You can also modify the structure of you file, by blanking
- lines you want to replace, and adding your new records at the
- first blank line which is long enough to store your new string.
- The blanking status of a line can be found on its first character
- so that you can count the length until the neline character, then
- see if it is also a blank line (then rewrite the newline with
- a blank). Don't forget: a NewLine under DOS is a couple of characters
- even though you get only one char using getc() on a text file.
-
-